#!/bin/bash

# Run a test or tests simply and include the bootstrap file
# By default this will also create a coverage report
# Command line option of -n will not generate a coverage report

printUsage() {
    echo "Usage: $0 [-n] [-t] [-f] path-or-file"
    echo "  Options: "
    echo "  -n  No code coverage report"
}

# Directive to generate a code coverage report
COVERAGE=true

# Process options
while getopts "n" opt; do
    case $opt in
        n)
            COVERAGE=false
            ;;
        \?)
            printUsage
            exit 1
            ;;
    esac
done

# Shift off used args
shift $((OPTIND-1))

if [ -z "$1" ]; then
    echo "Missing path to test file(s)."
    exit 2
fi

printf "\E[34m" # Change text color to blue

if [ "$COVERAGE" == "true" ] ; then
    phpunit --bootstrap=bootstrap.php --coverage-clover=coverage.xml $1 
else
    echo "Running tests without generating a coverage report"
    phpunit --bootstrap=bootstrap.php $1 
fi

# Switch text color back to default
tput op
